<form id="BasketForm" class="ep-metaparse ep.uiForm()" method="post" action="#FUNCTION("BASEURL", #Shop, 1)?ObjectID=#ObjectID">
#MENU("Message")#INCLUDE(#Template)#ENDMENU
<div class="CheckoutButtons">
  <div id="BasketButtons">

    <span id="RefreshButtonTop" class="HideElement Refresh FloatRight">
      <button type="submit" class="ep-metaparse ep.uiInput()" name="Save" value="{Update}" onclick="ep.local.setRefreshAction(this)">
        <span class="ep-sprite ep-sprite-xs Icon RefreshIconSmall"></span>{Update}
      </button>
    </span>
    <span id="CheckOutTop" class="FloatRight #IF(NOT #IsMinOrderAmountReached OR NOT #COUNT(#LineItemContainer.LineItems)) Disabled#ENDIF DoOrder">
      <button type="submit" class="ep-metaparse ep.uiInput()" name="SaveAndDoOrder" value="{CheckOut}" onclick="jq('#ChangeAction').val('SaveAndDoOrder');" #IF(NOT #IsMinOrderAmountReached OR NOT #COUNT(#LineItemContainer.LineItems)) disabled="disabled"#ENDIF >
        <span class="ep-sprite ep-sprite-xs Icon ContinueIconTiny"></span>{CheckOut}
      </button>
    </span>
  </div>
#MENU("CheckoutButton")#INCLUDE(#Template)#ENDMENU
</div>

<div class="ClearBoth BottomMargin" style="width: 100%; height: 1px; line-height: 1px;"></div>
#LOCAL("BasketId",#ID)
  <div class="Basket">
    <input type="hidden" name="ChangeAction" id="ChangeAction" value="Button" />
    <input type="hidden" name="ValidButton" value="Save" />
    <input type="hidden" name="ValidButton" value="SaveAndDoOrder" />
    #IF(#Session.SessionID)
    <input type="hidden" name="SessionID" value="#Session.SessionID" />
    #ENDIF

    #LOCAL("Alternate", 0)#WITH(#LineItemContainer)
    <table class="Basket" summary="{BasketTable}" id="BasketTable">
      <tr class="AlternateRow">
        <th class="SeparateColumn SlimColumn" >{Quantity}</th>
        <th class="SeparateColumn">{Name}</th>
        <th class="SeparateColumn SlimColumn NoWrap" title="{BasePriceAbr}">Unit Price</th>
        <th class="SeparateColumn SlimColumn" id="DiscountTableColumn">{Discount}</th>
        <th class="SeparateColumn SlimColumn" title="{LineItemPriceLong}">Total Price</th>
        <th class="SlimColumn"></th>
      </tr>
  #LOOP(#LineItems)
    #INCLUDE("ContentLine")
  #ENDLOOP
      #IF(#LineItemContainer.HasPrepayment)
      #IF(#COUNT(#LineItems) > 1)
      <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
        <td colspan="2" class="SeparateColumn">{LineItemsSubTotal}</td>
        <td class="SeparateColumn"></td>
        <td class="SeparateColumn"></td>
        <td class="SeparateColumn Money">#OriginalPriceSubTotal[money]</td>
        <td></td>
      </tr>
      #ENDIF
      <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
        <td colspan="2" class="SeparateColumn">{PrepaymentFor} #PrepaymentTotalBase[money]</td>
        <td class="SeparateColumn"></td>
        <td class="SeparateColumn"></td>
        <td class="SeparateColumn Money">#PrepaymentTotal[money]</td>
        <td></td>
      </tr>
      #ENDIF
      <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
        <td colspan="2" class="SeparateColumn">{LineItemsSubTotal}</td>
        <td class="SeparateColumn"></td>
        <td class="SeparateColumn"></td>
        <td class="SeparateColumn Money">#LineItemsSubTotal[money]</td>
        <td></td>
      </tr>
  #MENU("SalesDiscounts")#INCLUDE(#Template)#ENDMENU
  #LOOP(#SalesDiscounts)
    #INCLUDE("ContentLine")
  #ENDLOOP
  #LOOP(#Discounts)
    #INCLUDE("ContentLine")
  #ENDLOOP
  #IF(#Shipping)#WITH(#Shipping)
    #INCLUDE("ContentLine")
  #ENDWITH#ENDIF
  #IF(#Payment)#WITH(#Payment)
    #INCLUDE("ContentLine")
  #ENDWITH#ENDIF
  #IF(#DEFINED(#PaymentDiscount))#WITH(#PaymentDiscount)
    #INCLUDE("ContentLine")
  #ENDWITH#ENDIF
  #LOOP(#Statics)
    #INCLUDE("ContentLine")
  #ENDLOOP
  #IF(#Shop.CanSelectTaxAreaOnBasket)
      <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
        <td class="SeparateColumn">{TaxArea}</td>
        <td class="SeparateColumn">
          <select name="TaxArea" class="ep-metaparse ep.uiInput()" title="{SelectTaxArea}" onchange="DeactivateButton(jq('#CheckOut'));DeactivateButton(jq('#CheckOutTop'));ep.local.setRefreshAction(this);this.form.submit()">
          #LOOP(#Shop.TaxMatrix.TaxAreas)
            <option value="#ID" #IF(#TaxArea.ID == #ID)selected="selected"#ENDIF>#NameOrAlias</option>
          #ENDLOOP
          </select>
        </td>
        <td class="SeparateColumn"></td>
        <td class="SeparateColumn"></td>
        <td class="SeparateColumn"></td>
        <td></td>
      </tr>
  #ENDIF
  #LOCAL("EmptyTaxLineItem",0)
  #IF(#TaxModel)<!-- gross -->
    #LOOP(#Taxes)#LOCAL("LocalTaxRate", #FUNCTION("TaxRateForDefaultTaxArea", #Shop.Object, #TaxClass.Object))
      #IF(#LineItemPrice)
      <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
        <td colspan="2" class="SeparateColumn" >#IF(#LineItemPrice < 0){TaxAbatement}#ELSE#SPACE[0]{TaxAddition}#ENDIF:  #NameOrAlias (#CALCULATE(#LocalTaxRate*100) %)</td>
        <td class="SeparateColumn"></td>
        <td class="SeparateColumn"></td>
        <td class="SeparateColumn Money">#LineItemPrice[money]</td>
        <td></td>
      </tr>
      #ENDIF
    #ENDLOCAL#ENDLOOP
      <tr class="SeparateRow Total #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
        <td colspan="2" class="SeparateColumn GrandTotal">{GrandTotal}</td>
        <td class="SeparateColumn"></td>
        <td class="SeparateColumn"></td>
        <td class="Total SeparateColumn" >#GrandTotal[money]</td>
        <td></td>
      </tr>

  #IF(#Shop.VATreleased)
      <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
        <td colspan="5" class="SeparateColumn">#Shop.VATreleasedMessage</td>
        <td></td>
      </tr>
  #ELSE
    #IF(#Shop.TaxCalculationAfterAddress)
      <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
        <td colspan="6" class="SeparateColumn">{TaxCalculationAfterAddress}</td>
      </tr>
    #ELSE
        <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
          <td colspan="2" class="SeparateColumn">{TotalBeforeTax}</td>
          <td class="SeparateColumn"></td>
          <td class="SeparateColumn"></td>
          <td class="SeparateColumn Money">#TotalBeforeTax[money]</td>
          <td></td>
        </tr>
      #ENDIF
    #LOOP(#Taxes)
        #IF(#DEFINED(#TaxAmount) AND #TaxAmount != 0)
        <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
          <td colspan="2" class="SeparateColumn">{IncludedTaxAmount}: #NameOrAlias  (#CALCULATE(#TaxRate*100) %)</td>
          <td class="SeparateColumn"></td>
          <td class="SeparateColumn"></td>
          <td class="SeparateColumn Money">#TaxAmount[money]</td>
          <td></td>
        </tr>
        #ELSE
          #SET("EmptyTaxLineItem",#EmptyTaxLineItem+1)
        #ENDIF
    #ENDLOOP

  #IF(#CALCULATE(#COUNT(#Taxes)-#EmptyTaxLineItem) > 1)
      <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
        <td colspan="2" class="SeparateColumn">{TotalTax}</td>
        <td class="SeparateColumn"></td>
        <td class="SeparateColumn"></td>
        <td class="SeparateColumn Money">#TotalTax[money]</td>
        <td></td>
      </tr>
  #ENDIF
  #ENDIF

#ELSE<!-- net -->
  #IF(NOT #Shop.VATreleased)
    #IF(#Shop.TaxCalculationAfterAddress)
      <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
        <td colspan="6" class="SeparateColumn">{TaxCalculationAfterAddress}</td>
      </tr>
    #ELSE
        <tr class="SeparateRow Total #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
          <td colspan="2" class="SeparateColumn">{TotalBeforeTax}</td>
          <td class="SeparateColumn"></td>
          <td class="SeparateColumn"></td>
          <td class="Total SeparateColumn">#TotalBeforeTax[money]</td>
          <td></td>
        </tr>
    #ENDIF
    #LOOP(#Taxes)
      #IF(#DEFINED(#TaxAmount) AND #TaxAmount != 0)
        <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
          <td colspan="2"  class="SeparateColumn">{TaxRateFull}: #NameOrAlias (#CALCULATE(#TaxRate*100) %)</td>
          <td class="SeparateColumn"></td>
          <td class="SeparateColumn"></td>
          <td class="SeparateColumn Money">#TaxAmount[money]</td>
          <td></td>
        </tr>
      #ELSE
        #SET("EmptyTaxLineItem",#EmptyTaxLineItem+1)
      #ENDIF
    #ENDLOOP
  #ENDIF

  #IF(#CALCULATE(#COUNT(#Taxes)-#EmptyTaxLineItem) > 1)
    <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
      <td colspan="2"  class="SeparateColumn">{TotalTax}</td>
      <td class="SeparateColumn"></td>
      <td class="SeparateColumn"></td>
      <td class="SeparateColumn Money">#TotalTax[money]</td>
      <td></td>
    </tr>
  #ENDIF
    <tr class="SeparateRow Total #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
      <td colspan="2"  class="SeparateColumn">{GrandTotal}</td>
      <td class="SeparateColumn"></td>
      <td class="SeparateColumn"></td>
      <td class="SeparateColumn Total">#GrandTotal[money]</td>
      <td></td>
    </tr>
  #IF(#Shop.VATreleased AND #Shop.VATreleasedMessage)
    <tr class="SeparateRow #IF(#Alternate)AlternateRow#ENDIF">#SET("Alternate", 1 - #Alternate)
      <td colspan="5" class="SeparateColumn">#Shop.VATreleasedMessage</td>
      <td></td>
    </tr>
  #ENDIF
  #ENDIF#ENDLOCAL
  #ENDWITH#ENDLOCAL
    </table>
#ENDLOCAL
#WITH(#LineItemContainer)
 #IF(#Shop.FeatureMaxValue.PaymentNote AND #Payment.PaymentMethod.Note)<br />#Payment.PaymentMethod.Note[0]#ENDIF
 #IF(#Shop.FeatureMaxValue.DeliveryNote AND #Shipping.ShippingMethod.Note)<br />#Shipping.ShippingMethod.Note[0]#ENDIF
#ENDWITH
      <div class="ShippingOptionContainer">
        <div>
          {CustomerComment}:
        </div>
        <div class="HalfWidth FloatLeft">
          <div class="RightPadding">
            <textarea id="CustomerComment" class="BasketComment ep-metaparse ep.uiInput()" name="CustomerComment" rows="3" cols="200" onchange="ep.local.showRefreshButton();" onkeydown="ep.local.showRefreshButton();">#CustomerComment</textarea>
          </div>
        </div>

        <div class="HalfWidth FloatRight" style="width:49%">
          #MENU("AdditionalItems")#INCLUDE(#Template)#ENDMENU
        </div>
        <div class="ClearBoth MinimizeHeight"></div>
      </div>
  </div>
  <div class="OrderProcessNavigation">
    <span id="RefreshButton" class="HideElement Refresh FloatRight">
      <button type="submit" class="ep-metaparse ep.uiInput()" name="Save" value="" onclick="ep.local.setRefreshAction(this)">
        <span class="ep-sprite ep-sprite-xs Icon RefreshIconSmall"></span>{Update}
      </button>
    </span>
    <span id="CheckOut" class="FloatRight #IF(NOT #IsMinOrderAmountReached OR NOT #COUNT(#LineItemContainer.LineItems)) Disabled#ENDIF DoOrder">
      <button type="submit" class="ep-metaparse ep.uiInput()" name="SaveAndDoOrder" value="" onclick="jq('#ChangeAction').val('SaveAndDoOrder');" #IF(NOT #IsMinOrderAmountReached OR NOT #COUNT(#LineItemContainer.LineItems)) disabled="disabled"#ENDIF >
        <span class="ep-sprite ep-sprite-xs Icon ContinueIconTiny"></span>{CheckOut}
      </button>
    </span>
    <noscript>
    <div>
      <button type="submit" class="ep-metaparse ep.uiInput()" name="Save" value="{Update}" onclick="ep.local.setRefreshAction(this)">
        <span class="ep-sprite ep-sprite-xs Icon RefreshIconSmall"></span>{Update}
      </button>
    </div>
    </noscript>
  </div>
</form>

<div class="Separator"></div>
<script type="text/javascript">
//<![CDATA[
  ep.local.showRefreshButton = function() {
    jq('#RefreshButton, #RefreshButtonTop').removeClass('HideElement');
    jq('#CheckOut, #CheckOutTop, .MiniCheckoutLink').addClass('HideElement');
  };
  ep.local.setRefreshAction = function(node) {
    jq('#ChangeAction').val('Save');
    epages.setFormAction(node.form, '?ObjectID=#ObjectID');
  };

  ep.ready( function() {
  
    ep.require('ep.fn.equal');
    ep('#BasketTable select').equalWidth();

	  var basketTable = $("BasketTable");
	  var basketTableRows = basketTable.rows;
	  var basketTableRowsLength = basketTable.rows.length;
	  var discountTH = $("DiscountTableColumn");
	  var discountCellIndex = discountTH.cellIndex;
	  var discountCellOffsetLeft = discountTH.offsetLeft;

	  var discountCells = [];
	  for(var i = 0; i < basketTableRowsLength; i++) {
	    var currentCell = basketTableRows[i].cells[discountCellIndex];
	    var calcCellIndex = discountCellIndex;
	    while(!currentCell) {
	      calcCellIndex--;
	      currentCell = basketTableRows[i].cells[calcCellIndex];
	    }
	    var cells = currentCell.parentNode.cells;
	    for(var k = 0; k < cells.length; k++) {
	      var colspan = parseInt(cells[k].getAttribute("colspan"));
	      if((colspan || 0) > 1 && colspan > 1) {
	        calcCellIndex = calcCellIndex - colspan + 1;
	      }
	    }
	    if(calcCellIndex > 0) {
	      currentCell = basketTableRows[i].cells[calcCellIndex];
	      currentCellColspan = currentCell.getAttribute("colspan");
	      if(isNaN(currentCellColspan) || currentCellColspan < 2) {
	        discountCells.push(currentCell);
	      }
	    }
	  }

	  var hideDiscountColumn = function() {
	    for(var i = 0; i < discountCells.length; i++) {
	      dojo.addClass(discountCells[i], "HideElement");
	    }
	  };

	  var showDiscountColumn = function() {
	    for(var i = 0; i < discountCells.length; i++) {
	      dojo.removeClass(discountCells[i], "HideElement");
	    }
	  };

	  var cellsEmpty = true;
	  for(var i = 1; i < discountCells.length; i++) {
	    var innerCont = discountCells[i].innerHTML;

	    if(innerCont.length > 1 && !innerCont.match(/^\s*$/)) {
	      cellsEmpty = false;
	    }
	  }

	  if(cellsEmpty) {
	    hideDiscountColumn();

	    // this is definitely not pretty ...
	    // foreach cell look for a colspan. If the colspan is higher or equal to the discount index, we have to
	    // decrease its value as that cell should extend over the hidden discount cell
	    for(var x = 0; x < basketTableRowsLength; x++) {
	      var allCells = basketTableRows[x].cells[0].parentNode.cells;
	      for(var y = 0, yLength = allCells.length; y < yLength; y++) {
	        var cell = allCells[y];
	        var cellColspan = parseInt(cell.getAttribute("colSpan"));
	        if(cellColspan && cellColspan > 1 && cellColspan >= discountCellIndex) {
	          cell.setAttribute("colSpan", cellColspan-1);
	        }
	      }
	    }
	  }
  });
//]]>
</script>